import java.util.Scanner;

public class Login {
    String name = "YJH";
    String password = "123456";
    public void Test(String uname, String upassword)throws PassWordException,UserNameException{
            //异常的自定义使用
            if(!this.name.equals(uname)){
                throw new UserNameException("用户名输入错误，请重新输入用户名");
            }
            if(!this.password.equals(upassword)){
                throw new PassWordException("密码输入错误");
            }

    }
    public static void main(String[] args) {
        String uname;
        String upassword;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        uname = scanner.nextLine();
        System.out.println("请输入密码");
        upassword = scanner.nextLine();
        Login login = new Login();
        login.Test(uname,upassword);
        try {
            login.Test(uname,upassword);
        }catch (UserNameException e){
            e.printStackTrace();
        }catch (PassWordException e){
            e.printStackTrace();
        }
    }

}
